﻿using DAO.BaseDAO;
using DAO.DAOUtils;
using DTO.BaseDTO;
using DTO.DTOUtils;
using DTO.TeacherModule;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DAO.TeacherModule
{
    public class TeacherDAO
    {
        public DataTable GetAll()
        {
            List<Parameter> listParam = new List<Parameter>();
            return SQLUtils.ExcuteQuery("TeacherGetAll", ref listParam);
        }

        public bool Insert(ref TeacherDTO teacher)
        {
            bool res = true;
            RealAddressDAO addressDAO = new RealAddressDAO();

            RealAddressDTO addressDTO = teacher.AddressBirt;
            res = addressDAO.InsertAddressOnly(ref addressDTO);
            teacher.AddressBirt = addressDTO;
            
            addressDTO = teacher.AddressCurr;
            res = res && addressDAO.InsertAddressOnly(ref addressDTO);
            teacher.AddressCurr = addressDTO;

            teacher = (TeacherDTO)(new PersonDAO()).Insert(teacher);
            List<Parameter> listParam = GetListParam(teacher);
            res = SQLUtils.ExcuteNoneQuery("TeacherInsert", ref listParam);

            return res && teacher == null;
        }

        public List<Parameter> GetListParam(TeacherDTO teacher)
        {
            List<Parameter> listParam = new List<Parameter>();
            listParam.Add(new Parameter(DTOConstant.PersonId, teacher.Id));
            listParam.Add(new Parameter(DTOConstant.TeacherId, teacher.TeacherId));
            listParam.Add(new Parameter(DTOConstant.TeacherDateOfWork, teacher.TeacherDateOfWork));
            return listParam;
        }
    }
}
